﻿@model string

@{
    ViewBag.Title = "Configurar Atributos";
}

<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title" id="myModalLabel">@ViewBag.Title</h4>
</div>

@using (Html.BeginForm())
{
    <div class="modal-body">
        <div id="demoTree">
        </div>
    </div>
   
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal">Cancelar</button>
        <input type="submit" value="Salvar" class="btn btn-primary" />
    </div>
}

<script type="text/javascript">
    treeModel = @Html.Raw(Model)
</script>

<script src="@Url.Content("~/Scripts/jquery.jstree.js")" type="text/javascript"></script>

<script type="text/javascript">
    
    (function ($) {
        $("#demoTree").jstree({
            json_data: {
                data: treeModel
            },
            checkbox: {
                real_checkboxes: true,
                override_ui: true,
                real_checkboxes_names: function (n) {
                    return [("check_" + (n[0].id || Math.ceil(Math.random() * 10000))), n[0].id]
                }
            },
            plugins: ["themes", "json_data", "ui", "checkbox"]
        }).bind("loaded.jstree", function (event, data) {
            $('#demoTree').jstree('check_node', 'li[selected=selected]');
        });
    })(jQuery);

</script>